<template>
	<view class="main">
		<view class="top">
			<view class="flex-item">
				<picker mode="date" :value="currentDateStart || '开始时间'" @change="startTimeConfirm">
					<view style="display: none;">
						<input name="birthday" :value="currentDateStart" disabled></input>
					</view>
					<view class="picker">
						{{currentDateStart || '开始时间'}}
					</view>
				</picker>
				<view class="icon">
					<u-icon label="" name="arrow-up-fill" id="action"></u-icon>
					<u-icon label="" name="arrow-down-fill"></u-icon>
				</view>
			</view>
			<view class="flex-item">
				<picker mode="date" :value="currentDateEnd || '结束时间'" @change="endTimeConfirm">
					<view style="display: none;">
						<input name="birthday" :value="currentDateEnd" disabled></input>
					</view>
					<view class="picker">
						{{currentDateEnd|| '结束时间'}}
					</view>
				</picker>
				<view class="icon">
					<u-icon label="" name="arrow-up-fill" id="action"></u-icon>
					<u-icon label="" name="arrow-down-fill"></u-icon>
				</view>
			</view>
		</view>
		<view class="list_div">
			<u-list @scrolltolower="scrolltolower">
				<view class="list_item" v-for="(item, ind) in dataList" :key="ind"
					@tap="$wanlshop.to(`/pages/user/record/InvitationDetails?id=${item.id}`)">
					<view class="right">
						<view class="right_top">
							<view class="h3_span">
								<h3>{{ item.name }}</h3>
								<span>{{ item.mobile }}</span>
							</view>
							<span class="tip">{{ item.server_content }}</span>
						</view>
						<span>{{ item.day }} {{item.time}}</span>
						<view class="date_time">
							<view class="address">
								<span>{{ item.address }}</span>
								<image src="@/static/test/address.png" mode=""></image>
							</view>
							<view class="btn">
								<view class="button canBtn" @click.stop="cancelHandle(item)">取消</view>
								<view class="button comBtn" @click.stop="comHandle(item)">完成</view>
							</view>
						</view>
					</view>
				</view>
			</u-list>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				minDate: new Date(2020, 0, 1),
				maxDate: new Date(2030, 10, 1),
				showStartTime: false,
				currentDateStart: '',
				showEndTime: false,
				currentDateEnd: '',
				dataList: [],
				pageNo: 1,
				pageSize: 10
			};
		},
		mounted() {
			this.getData();
		},
		methods: {
			startTimeConfirm(e) {
				this.currentDateStart = e.detail.value
				this.getData()
				// this.showStartTime = false
			},
			endTimeConfirm(e) {
				this.currentDateEnd = e.detail.value
				this.getData()
				// this.showEndTime = false
			},
			// 上拉加载
			scrolltolower() {
				this.pageNo++;
				this.getData();
			},
			// 列表数据
			async getData() {
				let data = {
					start_time: this.currentDateStart,
					end_time: this.currentDateEnd,
					pageNo: this.pageNo,
					pageSize: this.pageSize
				};
				console.log(data);
				// return;
				await uni.request({
					url: '/worker/get_yao_list',
					method: 'POST',
					data,
					success: (res) => {
						if (res.res.code == 1) {
							this.dataList = res.res.data
						} else {
							this.$wanlshop.msg(res.msg || '请求失败！');
						}
					}
				});
			},
			// 取消邀约
			async cancelHandle(item) {
				let data = {
					id: item.id
				};
				console.log(data);
				// return;
				await uni.request({
					url: '/worker/cancel_yao',
					method: 'POST',
					data,
					success: (res) => {
						if (res.code == 200) {
							this.getData();
						} else {
							this.$wanlshop.msg(res.msg || '取消失败！');
						}
					}
				});
			},
			// 完成订单
			async comHandle(item) {
				let data = {
					id: item.id
				};
				console.log(data);
				// return;
				await uni.request({
					url: '/worker/success_yao',
					method: 'POST',
					data,
					success: (res) => {
						if (res.code == 200) {
							this.getData();
						} else {
							this.$wanlshop.msg(res.msg || '取消失败！');
						}
					}
				});
			}
		}
	};
</script>

<style scoped lang="less">
	.main {
		overflow: none;
		.top {
			background-color: #fff;
			display: flex;
			justify-content: space-between;
			width: 100%;
			height: 88rpx;
			padding: 0rpx 150rpx 0rpx;

			.flex-item {
				height: 80rpx;
				display: flex;
				align-items: center;
				font-size: 26rpx;

				span {
					display: inline-block;
					line-height: 34rpx;
					line-height: 30rpx;
					margin-right: 10rpx;
				}

				.icon {
					margin-top: -10rpx;
				}
			}
		}

		.list_div {
			height: calc(100vh - 200rpx);
			overflow-y: scroll;
			padding: 20rpx 34rpx;

			.list_item {
				display: flex;
				height: 192rpx;
				padding: 20rpx;
				background-color: #fff;
				border-radius: 8rpx;
				margin-bottom: 20rpx;

				.right {
					flex: 1;
					display: flex;
					justify-content: space-between;
					flex-direction: column;

					.right_top {
						width: 100%;
						display: flex;
						align-items: center;
						justify-content: space-between;

						.h3_span {
							display: flex;
							align-items: center;

							h3 {
								margin-right: 23rpx;
							}

							span {
								font-size: 26rpx;
								color: #fe6600;
							}
						}

						.tip {
							// width: 112rpx;
							height: 32rpx;
							padding: 0 10rpx;
							font-size: 22rpx;
							color: #fe6600;
							line-height: 32rpx;
							text-align: center;
							// padding: 0rpx 10rpx;
							border-radius: 4rpx;
							background-color: #fff0e5;
						}

						.button {
							width: 124rpx;
							height: 54rpx;
							background-color: #f5f5f5;
							border-radius: 27rpx;
							text-align: center;
							line-height: 54rpx;
							float: left;
							color: #656565;
						}
					}

					.date_time {
						font-size: 28rpx;
						display: flex;
						justify-content: space-between;
						align-items: center;

						.address {
							span {
								color: #999999;
								margin-right: 6rpx;
							}

							image {
								width: 28rpx;
								height: 28rpx;
							}
						}

						.btn {
							display: flex;

							.button {
								width: 124rpx;
								height: 56rpx;
								border-radius: 28rpx;
								text-align: center;
								line-height: 52rpx;
							}

							.canBtn {
								background-color: #f5f5f5;
								color: #636363;
							}

							.comBtn {
								margin-left: 20rpx;
								background-color: #fe6600;
								color: #fff;
							}
						}
					}
				}
			}
		}
	}

	/deep/ .flex-item .icon .u-icon__icon:last-child {
		margin-top: -4rpx;
	}

	/deep/ .flex-item .u-icon__icon span {
		height: 16rpx;
		color: #999;
		font-size: 14rpx;
	}
</style>